package no.zsoft.faktura.admin.repository;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
public class TenantRepository {
	@Autowired
	JdbcTemplate jdbcTemplate;
	@Transactional
	public void createTenant(String tenant){
		jdbcTemplate.execute("create database "+tenant);
		jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS "+tenant+".user (`id` bigint(20) NOT NULL AUTO_INCREMENT,`name` varchar(25) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;");
		jdbcTemplate.execute("INSERT INTO "+tenant+".user (`id`, `name`) VALUES (3, '"+tenant+"Db');");
	}
}
